<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <title>boost 搜索引擎</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        html, body {
            height: 100%;
        }

        body {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
        }

        .container {
            width: 800px;
            margin-top: -100px; /* 垂直居中微调 */
        }

        .search {
            display: flex;
            width: 100%;
            height: 52px;
            margin-bottom: 20px;
        }

        .search input {
            flex: 1;
            height: 50px;
            border: 1px solid #ccc;
            border-right: none;
            padding: 0 20px;
            font-size: 16px;
            border-radius: 25px 0 0 25px;
        }

        .search button {
            width: 150px;
            height: 52px;
            background: #4e6ef2;
            border: none;
            color: white;
            font-size: 18px;
            cursor: pointer;
            border-radius: 0 25px 25px 0;
            transition: background 0.3s;
        }

        .search button:hover {
            background: #3a4fab;
        }

        .result {
            width: 100%;
        }

        .item {
            margin: 15px 0;
            padding: 15px;
            border-radius: 8px;
            background: #f8f9fa;
        }

        .item a {
            display: block;
            text-decoration: none;
            font-size: 20px;
            color: #4e6ef2;
            margin-bottom: 8px;
        }

        .item a:hover {
            text-decoration: underline;
        }

        .item p {
            color: #555;
            font-size: 16px;
            line-height: 1.5;
        }

        .item i {
            display: block;
            color: #008000;
            font-style: normal;
            margin-top: 8px;
            font-size: 14px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="search">
            <input type="text" placeholder="请输入搜索关键字">
            <button onclick="Search()">搜索一下</button>
        </div>
        <div class="result"></div>
    </div>

    <script>
        function Search() {
            const query = $(".search input").val().trim();
            if (!query) return;

            $.ajax({
                type: "GET",
                url: `/s?word=${encodeURIComponent(query)}`,
                success: function(data) {
                    BuildHtml(data);
                },
                error: function() {
                    alert("搜索请求失败，请稍后重试");
                }
            });
        }

        function BuildHtml(data) {
            const resultContainer = $(".result").empty();
            
            data.forEach(item => {
                const itemDiv = $("<div>").addClass("item");
                $("<a>", {
                    href: item.url,
                    text: item.title,
                    target: "_blank"
                }).appendTo(itemDiv);
                
                $("<p>", {
                    text: item.desc
                }).appendTo(itemDiv);
                
                $("<i>", {
                    text: item.url
                }).appendTo(itemDiv);
                
                itemDiv.appendTo(resultContainer);
            });
        }
    </script>
</body>
</html>